package com.hulk.other.springStudy.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

import com.hulk.other.springStudy.proxy.service.PersionServiceImpl;

/**
 * JDK的Proxy实现代理要求被代理的目标对象必须实现一个接口
 * @author Administrator
 *
 */
public class ProxyFactory implements InvocationHandler {
	private Object target;

	public Object createPersionService(Object target) {
		this.target = target;
		return Proxy.newProxyInstance(this.target.getClass().getClassLoader(),
				this.target.getClass().getInterfaces(), this);
	}

	@Override
	public Object invoke(Object proxy, Method method, Object[] args)
			throws Throwable {
		PersionServiceImpl persionService = (PersionServiceImpl) target;
		Object result = null;
		System.out.println("代理执行：我的名字是："+persionService.getName());
		result = method.invoke(target, args);
		return result;
	}

}
